<h3>Search</h3>
<p>Search our collection of TV theme songs using the form below. </p>
<?php
if (isset($_GET['page'])) 
{
	$page = intval($_GET['page']);
}
else 
{
	$page = 1;
}
?>
<form name="formSear" class="searchform" action="search.php" method="g35">
	<input type="text" class="textbox" name="searWords" value="{searchWords}"/>
	<input name="Send" class="button" type="submit" value="Search" />
</form>
<br />
<?php
if(!empty($_GET['searWords']))
{
	$data = $tvtunes->gpc_check($_GET);
	if (!isset($data['searWords']{3}))
	{
		echo 'Please insert at least 3 characters';
	}
	else 
	{
		if (isset($data['page']))
		{
			$page = $data['page'];
		}
		else
		{
			$page = 1;
		}
		$start = ($page - 1)*20;
		//$res = mysql_query("SELECT file_name,file_title FROM bj_audio WHERE file_title  REGEXP('{$data['searWords']}') ORDER BY file_name") or die(mysql_error());
		//$res = mysql_query("SELECT file_name,file_title FROM bj_audio WHERE MATCH(file_name) AGAINST ('*{$data['searWords']}*' IN BOOLEAN MODE) ORDER BY file_name");
		$res = mysql_query("SELECT count(id_file) as nr FROM bj_audio WHERE MATCH(file_name) AGAINST ('*{$data['searWords']}*' IN BOOLEAN MODE) ORDER BY file_name");
		
		if ($res) 
		{
			while ($lin = mysql_fetch_assoc($res))
			{
				$rows = $lin['nr'];
			}
		}
		
		$pages = ceil($rows/20);
		$res = mysql_query("SELECT file_name,file_title FROM bj_audio WHERE MATCH(file_name) AGAINST ('*{$data['searWords']}*' IN BOOLEAN MODE) ORDER BY file_name LIMIT ".$start.",20");
		if ($res)
		{
			$cnt = 1 + ($page-1)*20;
			while ($lin = mysql_fetch_assoc($res))
			{
				echo $cnt . '.&nbsp;<a href="' . $tvtunes->create_href($lin['file_title']) .'">' . str_replace('.mp3', '', $lin['file_name']) . '</a><br>';
				$cnt ++;
			}
		}
		else
		{
			echo "<b> There are no results matching your keywords.<br>Please try again.</b>";
		}
		
		if ($pages > 1)
		{
			if ($page > 1)
			{
				echo '<a href="'.ABS_URL.'search.php?searWords='.$data['searWords'].'&search=Search&page='.($page-1).'"><b>Previous</b> | </a> ';
			}
			if ($page < $pages)
			{
				echo '<a href="'.ABS_URL.'search.php?searWords='.$data['searWords'].'&search=Search&page='.($page+1).'"><b>Next</b></a>';
			}
		}
	}
}//if empty searWords
?>